package chapter01.d01;

/**
 * 创建线程的2种方式
 * Created by kenneth on 2017/5/12.
 */
public class CreateThread {
	public static void main(String[] args) {
		Rabbit rabbit = new Rabbit();
		Thread tortoise = new Thread(new Tortoise());
		rabbit.start();
		tortoise.start();
	}
}

class Rabbit extends Thread {
	@Override
	public void run() {
		for (int i = 0; i < 100; i++) {
			System.out.println("兔子跑了" + i + "步");
			try {
				sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}

class Tortoise implements Runnable {
	 @Override
	public void run() {
		for (int i = 0; i < 100; i++) {
			System.out.println("乌龟跑了" + i + "步");
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}